<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"  xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="mall/advert/include::header"></head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>大礼包权限设置</h5>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="signupForm">
                        <input type="hidden" name="id" id="id" th:value="${activity.id}">

                        <div class="form-group">
                            <label class="col-sm-2 control-label">购买权限:</label>
                            <div class="col-sm-8">
                                <select data-placeholder="" class="form-control chosen-select"
                                        id="shopProductAuthorityId" name="shopProductAuthorityId">
                                    <option th:value="0">请选择购买权限</option>
                                    <option th:selected="${activity.shopProductAuthorityId}== ${item.id}"
                                            th:each="item: ${productAuthorityList}"
                                            th:text="${item.authorityName}"
                                            th:value="${item.id}">
                                    </option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-2 control-label">赠送权限:</label>
                            <div class="col-sm-8">
                                <select data-placeholder="" class="form-control chosen-select"
                                        id="handselProductAuthorityId" name="handselProductAuthorityId">
                                    <option th:value="0">请选择赠送权限</option>
                                    <option th:selected="${activity.handselProductAuthorityId}== ${item.id}"
                                            th:each="item: ${productAuthorityList}"
                                            th:text="${item.authorityName}"
                                            th:value="${item.id}">
                                    </option>
                                </select>
                            </div>
                        </div>


                        <div class="form-group text-center">
                            <div class="col-sm-8 col-sm-offset-2">
                                <button type="submit" class="btn btn-primary"><i class="fa fa-check"></i>提交</button>
                                <div class="btn btn-danger" onclick="closeDow()"><i class="fa fa-remove"></i> 关闭</div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<div th:include="mall/advert/include::footer"></div>
</script>
<script type="text/javascript">
    function closeDow() {
        var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
        parent.layer.close(index);
    }

    $().ready(function() {
        validateRule();
    });
    $.validator.setDefaults({
        submitHandler : function() {
            save();
        }
    });

    function save() {
        $.ajax({
            cache : true,
            type : "POST",
            url : "/activity/manage/updateAuthority",
            data : $('#signupForm').serialize(),// 你的formid
            async : false,
            error : function(request) {
                parent.layer.alert("Connection error");
            },
            success : function(data) {
                if (data.code == 0) {
                    parent.layer.msg("操作成功");
                    parent.reLoad();
                    var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                    parent.layer.close(index);
                } else {
                    if (data.msg) {
                        parent.layer.alert(data.msg)
                    }else {
                        window.location.href = "/";
                    }
                }

            }
        });
    }

    function validateRule() {
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#signupForm").validate({
            rules : {

            },
            messages : {

            }
        })
    }
</script>
</body>

</html>
